55.4 Boxfuse和Amazon Web Services

Boxfuse的工作机制是将你的Spring Boot可执行jar或war转换进一个最小化的VM镜像,该镜像不需改变就能部署到VirtualBox或AWS。Boxfuse深度集成Spring Boot并使用你的Spring Boot配置文件自动配置端口和健康检查URLs,它将该信息用于产生的镜像及它提供的所有资源(实例,安全分组,可伸缩的负载均衡等)。

一旦创建一个Boxfuse account,并将它连接到你的AWS账号,安装最新版Boxfuse客户端,你就能按照以下操作将Spring Boot应用部署到AWS(首先要确保应用被Maven或Gradle构建过,比如mvn clean package):

$ boxfuse run myapp-1.0.jar -env=prod

更多选项可查看boxfuse run文档,如果当前目录存在一个boxfuse.conf文件,Boxfuse将使用它。

如果你的可执行jar或war包含application-boxfuse.properties文件,Boxfuse默认在启动时会激活一个名为boxfuse的Spring profile,然后在该profile包含的属性基础上构建自己的配置。

此刻boxfuse将为你的应用创建一个镜像并上传到AWS,然后配置并启动需要的资源:

Fusing Image for myapp-1.0.jar ...
Image fused in 00:06.838s (53937 K) -> axelfontaine/myapp:1.0
Creating axelfontaine/myapp ...
Pushing axelfontaine/myapp:1.0 ...
Verifying axelfontaine/myapp:1.0 ...
Creating Elastic IP ...
Mapping myapp-axelfontaine.boxfuse.io to 52.28.233.167 ...
Waiting for AWS to create an AMI for axelfontaine/myapp:1.0 in eu-central-1 (this may take up to 50 seconds) ...
AMI created in 00:23.557s -> ami-d23f38cf
Creating security group boxfuse-sg_axelfontaine/myapp:1.0 ...
Launching t2.micro instance of axelfontaine/myapp:1.0 (ami-d23f38cf) in eu-central-1 ...
Instance launched in 00:30.306s -> i-92ef9f53
Waiting for AWS to boot Instance i-92ef9f53 and Payload to start at http://52.28.235.61/ ...
Payload started in 00:29.266s -> http://52.28.235.61/
Remapping Elastic IP 52.28.233.167 to i-92ef9f53 ...
Waiting 15s for AWS to complete Elastic IP Zero Downtime transition ...
Deployment completed successfully. axelfontaine/myapp:1.0 is up and running at http://myapp-axelfontaine.boxfuse.io/

你的应用现在应该已经在AWS上启动并运行了。

这里有篇在EC2部署Spring Boot应用的博客,Boxfuse官网也有Boxfuse集成Spring Boot文档,你可以拿来作为参考。